from selenium import webdriver
from time import sleep
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium import webdriver
# 导入 Service 类（关键）
from selenium.webdriver.chrome.service import Service

#实例化对象：

service = Service(executable_path="E:\\python\\python38\\chromedriver.exe")
driver = webdriver.Chrome(service=service)
driver.get("http://www.baidu.com")
action = ActionChains(driver)

driver.maximize_window()
sleep(5)

driver.add_cookie({'name':'BDUSS','value':'EVyVnNjQkdGSTNDOVFpZERGY2pvaFp3WkVyZ1hKUFVyY35pSzFwSFo2YWN'})
sleep(2)
cookies=driver.get_cookies()
print("cookies内容为",cookies)
for co in cookies:
    print(co['name'])

driver.refresh()

sleep(5)